Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Diagnostic Dumping Functionality #1443

Draft
wants to merge 39 commits into
base: develop
Choose a base branch
from

Conversation

mdaneri
Copy link
Contributor

@mdaneri mdaneri commented Nov 2, 2024

Description

This pull request introduces a new function, Invoke-PodeDump, to capture detailed diagnostic information during critical failures or fatal exceptions within Pode.

Key Features

  1. Configurable Dump Formats:

    • Supports formats such as JSON, YAML, CLIXML, Plain Text, and Binary.
  2. Pipeline Support:

    • The ErrorRecord parameter accepts pipeline input, simplifying integration with try-catch blocks.
  3. Dynamic Overrides:

    • Supports runtime overrides for Path and Format.
    • Default configuration options can be set in server.psd1.
  4. Optional Application Halt:

    • Includes a -Halt switch to terminate the application after saving the diagnostic dump.

Configuration in server.psd1

@{
    Server = @{
        Debug = @{
            Dump = @{
                Enable      = $true
                Format      = 'Yaml'
                Path        = './Dump'
                MaxDepth    = 5
            }
        }
    }
}
  • Enable: Enable or disable memory dump functionality.
  • Format: Set the default output format.
  • Path: Specify the directory for saving dump files.
  • MaxDepth: Define the maximum depth of information collection.

Example Usage

  1. Diagnostic Dump with Halt:

    try {
        throw [System.Exception] "Simulated exception"
    }
    catch {
        $_ | Invoke-PodeDump -Format 'json' -Halt
    }
  2. Custom Configuration Overrides:

    try {
        throw [System.Exception] "Simulated error"
    }
    catch {
        $_ | Invoke-PodeDump -Format 'yaml' -Path 'C:\CustomDumps'
    }

Notes

  • Automatically creates directories for the specified dump path if they do not exist.
  • Enhances Pode's error handling capabilities by providing detailed diagnostics for debugging.

# Invoke the method
$methodInfo.Invoke($Runspace.Debugger, @($eventArgs))

Write-Host "DebuggerStopEvent raised successfully."

Check warning

Code scanning / PSScriptAnalyzer

File 'Helpers.ps1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information. Warning

File 'Helpers.ps1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

src/Private/Dump.ps1 Fixed Show fixed Hide fixed
@mdaneri mdaneri changed the title Add Enhanced Diagnostic Dump Feature with Configurable Output Formats and Pipeline Support Add Enhanced Diagnostic Dump Feature with Configurable Output Formats Nov 5, 2024
@mdaneri mdaneri changed the title Add Enhanced Diagnostic Dump Feature with Configurable Output Formats Add Enhanced Diagnostic Dump Feature, Suspend-PodeServer and Resume-PodeServer Nov 5, 2024
Copy link
Owner

@Badgerati Badgerati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdaneri There's a fair few comments, but the most important ones are for the DebuggerHandler class, so I would recommend reading those first.

src/Private/Context.ps1 Outdated Show resolved Hide resolved
docs/Tutorials/ServerOperation/Restarting/Overview.md Outdated Show resolved Hide resolved
src/Public/Core.ps1 Outdated Show resolved Hide resolved
src/Public/Core.ps1 Outdated Show resolved Hide resolved
src/Public/Core.ps1 Outdated Show resolved Hide resolved
src/Private/Dump.ps1 Outdated Show resolved Hide resolved
src/Private/Dump.ps1 Outdated Show resolved Hide resolved
src/Private/Dump.ps1 Outdated Show resolved Hide resolved
src/Private/Dump.ps1 Outdated Show resolved Hide resolved
src/Private/Dump.ps1 Outdated Show resolved Hide resolved
src/Private/Server.ps1 Fixed Show fixed Hide fixed
@mdaneri mdaneri changed the title Add Enhanced Diagnostic Dump Feature, Suspend-PodeServer and Resume-PodeServer Add Diagnostic Dumping Functionality Dec 8, 2024
@mdaneri mdaneri marked this pull request as draft December 8, 2024 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants